﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sector7.Restaurant.EntityType;
using Sector7.Framework.Core;
using System.Data.SqlClient;
using Sector7.Framework.Enums;
using Sector7.Framework.DB;

namespace Sector7.Restaurant.DAO.OleDB
{
    public class MenuItemTypeDAO : IMenuItemTypeDAO
    {
        public List<RS_MenuItemType> ReadAll(bool isGreedy)
        {
            using (DBHelper opt = new DBHelper())
            {
                List<RS_MenuItemType> types = new List<RS_MenuItemType>();
                string sql = "SELECT * FROM RS_MetadataType WHERE (Usage & 2) = 2";

                SqlDataReader reader = opt.ExecuteQuery(sql);

                while (reader.Read())
                {
                    object type = new RS_MenuItemType();

                    DBUtil.ReadData(reader, ref type);

                    if (isGreedy)
                    {
                        IMenuItemDAO menuItemDAO = new MenuItemDAO();
                        (type as RS_MenuItemType).MenuItems = menuItemDAO.ReadAll((type as RS_MenuItemType).TypeId);
                    }

                    types.Add(type as RS_MenuItemType);
                }

                return types;
            }
        }
    }
}
